package com.wangjiyuan.giftshuo.ui.fragment.classify.shop;

import android.util.Log;

import com.wangjiyuan.giftshuo.bean.classifybean.shop.TreeBean;

import rx.Observable;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by QXL on 2016/11/18.
 */

public class ShopPresenter implements ShopContract.IShopPresenter {
    private ShopContract.IShopModel iShopModel;
    private ShopContract.IShopView iShopView;

    private Subscription subscribe;

    public ShopPresenter(ShopContract.IShopView view){
        iShopModel=new ShopModel();
        this.iShopView=view;
    }

    @Override
    public void getTreeObservable() {
        Observable<TreeBean> treeObservable = iShopModel.getTreeObservable();
        subscribe = treeObservable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<TreeBean>() {
                    @Override
                    public void onStart() {
                        super.onStart();
                        Log.e("Tag","start");
                    }

                    @Override
                    public void onCompleted() {
                        subscribe.unsubscribe();
                        Log.e("Tag","complete");
                    }

                    @Override
                    public void onError(Throwable e) {
                        subscribe.unsubscribe();
                        Log.e("Tag","error");
                    }

                    @Override
                    public void onNext(TreeBean bean) {
                        iShopView.loadTreeData(bean);
                    }
                });
    }
}
